import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/layout'
  },

  {
    path: '/seach',
    name: 'seach',
    component: () => import('../views/search/index.vue')

  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue')

  },
  {
    path: '/layout',

    component: () => import('../views/layout/index.vue'),
    children: [{
        path: '', // 默认子路由，只能有一个，当访问/的时候，显示home组件
        name: 'home',
        component: () => import('../views/home/inndex.vue')
      },
      {
        path: '/qa',
        name: 'qa',
        component: () => import('@/views/qa')
      },
      {
        path: '/video',
        name: 'video',
        component: () => import('@/views/video')
      },
      {
        path: '/my',
        name: 'my',
        component: () => import('@/views/my')
      }
    ]
  },
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article'),
    // 开启 Props 传参，说白了就是把路由参数映射到组件的 props 数据中
    props: true
  },
  {
    path: '/user/profile',
    name: 'user-profile',
    component: () => import('@/views/user-profile')
  }

]

const router = new VueRouter(

  {
    mode: 'history',
    base: process.env.BASE_URL,
    routes
  })

export default router
